﻿using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using QuanLyTuyenSinh.Base;
using QuanLyTuyenSinh.DataLayer;

namespace QuanLyTuyenSinh.BussinessLayer
{
    public class Ethnic
    {
        public DataConfig DataConfig;

        private DataTable dtTable;

        public Ethnic()
        {
            DataConfig = new DataConfig(frmLoading.Servername, frmLoading.UserName, frmLoading.Pass);
        }

        public int EthnicId { get; set; }
        public string EthnicName { get; set; }
              
       
        public int Insert(Ethnic obj)
        {
            int result = 0;
            string sql = string.Format("INSERT INTO Ethnic(EthnicName) values (N'{0}')", obj.EthnicName);
            try
            {
                result = DataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }

        public int Update(Ethnic obj)
        {
            int result = 0;
            string sql = string.Format("UPDATE Ethnic SET EthnicName= N'{0}' Where EthnicId= N'{1}'"
                                       , obj.EthnicName, obj.EthnicId);
            try
            {
                result = DataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }
        public int Delete(Ethnic obj)
        {
            int result = 0;
            string sql = string.Format("DELETE Ethnic  Where EthnicId= N'{0}'", obj.EthnicId);
            try
            {
                result = DataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }
    }
}